package file

import (
	"errors"
	"path"
)

func GetMimeType(filename string) (string, error) {
	ext := path.Ext(filename)
	if ext == "" {
		return "", errors.New("filename has no extension")
	} // 获取文件扩展名
	if ext == ".css" {
		return "text/css", nil
	} else if ext == ".js" {
		return "application/x-javascript", nil
	} else if ext == ".rar" {
		return "application/x-rar-compressed", nil
	} else if ext == ".jpg" || ext == ".jpeg" || ext == ".png" {
		return "image/jpeg", nil
	} else if ext == ".webp" {
		return "image/webp", nil
	} else if ext == ".7z" {
		return "application/x-7z-compressed", nil
	} else if ext == ".wgt" {
		return "application/widget", nil
	}
	return "", errors.New("unknown file extension")
}
